import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
/* Layout */
import Layout from '@/views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [{
  path: '/login',
  component: () =>
    import ('@/views/login/index'),
  hidden: true
},
  {
    path: '/404',
    component: () =>
      import ('@/views/404'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'home',
      component: () =>
        import ('@/views/home/index'),
      meta: {
        title: '首页',
        icon: 'el-icon-s-home'
      }
    }]
  },


]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/sys',
    component: Layout,
    redirect: 'admin',
    name: 'sysManage',
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-tools',
      permission: "sys"
    },
    children: [
      {
        path: 'admin',
        component: () => import ('@/views/sys/admin/index'),
        name: 'admin',
        meta: {
          title: '用户管理',
          icon: 'el-icon-s-tools',
          permission: "sys:admin"
        },
        children: []
      },
      {
        path: 'adminDetail',
        component: () => import ('@/views/sys/admin/detail'),
        name: 'adminDetail',
        meta: {
          title: '用户详情',
          icon: 'el-icon-s-tools',
          permission: "sys:admin:detail"
        },
        hidden: true,
        children: []
      },
      {
        path: 'role',
        component: () => import ('@/views/sys/role/index'),
        name: 'role',
        meta: {
          title: '角色管理',
          icon: 'el-icon-s-tools',
          permission: "sys:role"
        },
        children: []
      },
      {
        path: 'roleDetail',
        component: () => import ('@/views/sys/role/detail'),
        name: 'roleDetail',
        meta: {
          title: '角色详情',
          icon: 'el-icon-s-tools',
          permission: "sys:sys:detail"
        },
        hidden: true,
        children: []
      },
      {
        path: 'permission',
        component: () => import ('@/views/sys/permission/index'),
        name: 'permission',
        meta: {
          title: '权限管理',
          icon: 'el-icon-s-tools',
          permission: "sys:permission"
        },
        children: []
      },
      {
        path: 'permissionDetail',
        component: () => import ('@/views/sys/permission/detail'),
        name: 'permissionDetail',
        meta: {
          title: '权限详情',
          icon: 'el-icon-s-tools',
          permission: "sys:permission:detail"
        },
        hidden: true,
        children: []
      },
      {
        path: 'monitor',
        component: () => import ('@/views/sys/monitor/index'),
        name: 'monitor',
        meta: {
          title: '系统监控',
          icon: 'el-icon-s-tools',
          permission: "sys:hardware:info"
        },
        children: []
      },
    ]
  },
  {
    path: '/promotion',
    component: Layout,
    redirect: 'ad',
    name: 'promotion',
    meta: {
      title: '推广管理',
      icon: 'el-icon-s-tools',
      permission: "promotion"
    },
    children: [
      {
        path: 'ad',
        component: () => import ('@/views/promotion/ad/index'),
        name: 'ad',
        meta: {
          title: '广告管理',
          icon: 'el-icon-s-tools',
          permission: "promotion:ad"
        },
        children: []
      },
      {
        path: 'adDetail',
        component: () => import ('@/views/promotion/ad/detail'),
        name: 'adDetail',
        meta: {
          title: '广告详情',
          icon: 'el-icon-s-tools',
          permission: "promotion:ad:detail"
        },
        hidden: true,
        children: []
      },
    ]
  },
]
